<template>
	<view class="user-page-box">
		<view class="user-header-image"></view>
		<u-navbar title="个人中心" bgColor="transparent" leftIconColor="#ffffff" titleStyle="color:#ffffff;">
			<view slot="left"></view>
		</u-navbar>
		<view class="user-page" :style="{ top: $u.addUnit(44 + $u.sys().statusBarHeight, 'px') }">
			<view class="user-info-box" v-if="isLogin && userInfo">
				<image class="user-info-icon" :src="userInfo.avatar"></image>
				<view class="user-info-right">
					<view class="user-info">
						<view class="user-info-name">
							{{ userInfo.nickname }} {{ userInfo.mobile }}
						</view>
						<view class="user-info-tag" @click="navigatorPage('/pages/merchant/merchantList', true)">
							<image src="../../static/mine/icon_sore.png" class="image"></image>
							<view>积分:{{ userInfo.all_score }}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="user-info-box" v-if="!isLogin">
				<image class="user-info-icon" src="../../static/default_avatar.png"></image>
				<view class="user-info-right">
					<view class="user-info">
						<view class="user-info-name" @click="navigatorPage('/pages/login/login')">
							授权登录
						</view>
					</view>
				</view>
			</view>
			<view class="user-blance-box">
				<view class="user-blance-left">
					<view class="user-blance-number">
						{{ isLogin ? userInfo.fixed_score : "*****" }}
					</view>
					<view class="user-blance-title">固定积分</view>
				</view>
				<view class="user-blance-right">
					<view class="user-blance-number">
						{{ isLogin ? userInfo.score : "*****" }}
					</view>
					<view class="user-blance-title">自由积分</view>
				</view>
			</view>
			<view class="user-menu">
				<view class="menu-item" @click="navigatorPage('/pages/mine/myMonthCard', true)">
					<view class="left">
						<image class="menu-icon" src="../../static/mine/icon_kc.png"></image>
						<view class="menu-name">我的月卡</view>
					</view>
					<u-icon name="arrow-right"></u-icon>
				</view>
				<view class="menu-item" @click="navigatorPage('/pages/mine/exchangeRecord', true)">
					<view class="left">
						<image class="menu-icon" src="../../static/mine/icon_dh.png"></image>
						<view class="menu-name">我的兑换</view>
					</view>
					<u-icon name="arrow-right"></u-icon>
				</view>
				<view class="menu-item" @click="navigatorPage('/pages/mine/coursesReservation')">
					<view class="left">
						<image class="menu-icon" src="../../static/mine/icon_yy.png"></image>
						<view class="menu-name">我的预约</view>
					</view>
					<u-icon name="arrow-right"></u-icon>
				</view>
				<view class="menu-item" @click="navigatorPage('/pages/mine/myCoupon', true)">
					<view class="left">
						<image class="menu-icon" src="../../static/mine/icon_yh.png"></image>
						<view class="menu-name">我的优惠券</view>
					</view>
					<u-icon name="arrow-right"></u-icon>
				</view>
				<view class="menu-item" @click="navigatorPage('/pages/mine/scoreRecode', true)">
					<view class="left">
						<image class="menu-icon" src="../../static/mine/icon_jf.png"></image>
						<view class="menu-name">积分明细</view>
					</view>
					<u-icon name="arrow-right"></u-icon>
				</view>
				<view class="menu-item" @click="navigatorPage('/pages/reservation/activeRecord?back=1', true)">
					<view class="left">
						<image class="menu-icon" src="../../static/mine/icon_hd.png"></image>
						<view class="menu-name">我的活动</view>
					</view>
					<u-icon name="arrow-right"></u-icon>
				</view>

				<view class="menu-item" @click="navigatorPage('/pages/mine/myCourses', true)"
					v-if="userInfo.is_teacher">
					<view class="left">
						<image class="menu-icon" src="../../static/mine/icon_ls.png"></image>
						<view class="menu-name">我是老师</view>
					</view>
					<u-icon name="arrow-right"></u-icon>
				</view>
				<view class="menu-item" @click="navigatorPage('/pages-merchant/merchant/index', true)"
					v-if="userInfo.is_merchant||userInfo.is_examine">
					<view class="left">
						<image class="menu-icon" src="../../static/mine/icon_sj.png"></image>
						<view class="menu-name">我是商家</view>
					</view>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapGetters
	} from "vuex";
	export default {
		data() {
			return {
				userInfo: {
					fixed_score: "0.00",
					score: "0.00",
				},
			};
		},
		computed: mapGetters(["isLogin"]),
		onShow() {
			if (this.isLogin) {
				this.getUserInfo();
			}
		},
		methods: {
			//页面跳转
			navigatorPage(page, auth = false) {
				if (auth && !this.isLogin) {
					this.$Tips("/pages/login/login");
				} else {
					this.$Tips(page);
				}
			},
			//获取用户信息
			getUserInfo() {
				this.$Api.user.getUserInfo().then((res) => {
					this.userInfo = res.data.userinfo;
					this.$store.commit("UPDATE_USERINFO", res.data.userinfo);
				});
			},
		},
	};
</script>

<style>
	page {
		background: #f7f8fa;
	}
</style>

<style lang="scss">
	.user-page-box {
		position: relative;

		.user-header-image {
			width: 100%;
			height: 872rpx;
			background: linear-gradient(#a3c616 0%, #ddf79a 100%);
			position: absolute;
			top: 0;
			z-index: 1;
		}

		.user-page {
			width: 100%;
			position: absolute;
			z-index: 1;
		}

		.user-info-box {
			margin: 20rpx;
			position: relative;
			border-radius: 20rpx;
			display: flex;
			align-items: center;
			color: #ffffff;

			.user-info-icon {
				width: 116rpx;
				height: 116rpx;
				border-radius: 50%;
				border: 4rpx solid #ffffff;
			}

			.user-info-right {
				margin-left: 28rpx;

				.user-info {
					.user-info-name {
						font-weight: bold;
						font-size: 36rpx;
					}

					.user-info-tag {
						display: flex;
						align-items: center;
						width: max-content;
						padding: 8rpx 40rpx 8rpx 20rpx;
						background: #ffffff;
						border-radius: 28rpx;
						font-size: 32rpx;
						margin-top: 16rpx;
						color: #a3c616;

						.image {
							width: 30rpx;
							height: 24rpx;
							margin-right: 14rpx;
						}
					}
				}
			}
		}

		.user-blance-box {
			background: #ffffff;
			padding: 0 20rpx;
			height: 188rpx;
			margin: 52rpx 20rpx 20rpx 20rpx;
			position: relative;
			border-radius: 32rpx;
			display: flex;
			align-items: center;

			.user-blance-left,
			.user-blance-right {
				margin-left: 20rpx;
				flex: 1;
				color: #333333;

				.user-blance-title {
					text-align: center;
					font-size: 28rpx;
				}

				.user-blance-number {
					margin-top: 10rpx;
					font-weight: bold;
					font-size: 44rpx;
					text-align: center;
				}
			}
		}

		.user-menu {
			padding: 30rpx;
			margin: 24rpx;
			border-radius: 20rpx;
			background: #fff;

			.menu-item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 40rpx;

				.left {
					display: flex;
					align-items: center;
					line-height: 24rpx;

					.menu-icon {
						width: 60rpx;
						height: 60rpx;
					}

					.menu-name {
						font-size: 28rpx;
						margin-left: 24rpx;
						color: #333;
					}
				}

				.menu-number {
					font-size: 30rpx;
					color: #666666;
					letter-spacing: 2rpx;
				}
			}

			.menu-item:first-child {
				margin-top: 0;
			}
		}
	}
</style>